package org.eiahe.hr.employeeRelation.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.ehe.common.core.BaseController;
import org.ehe.common.core.domain.R;
import org.ehe.common.core.validate.AddGroup;
import org.ehe.common.core.validate.EditGroup;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.mybatis.core.page.PageQuery;
import org.ehe.common.mybatis.core.page.TableDataInfo;
import org.eiahe.hr.employeeRelation.domain.bo.TechnologyAgreementBo;
import org.eiahe.hr.employeeRelation.domain.vo.TechnologyAgreementVo;
import org.eiahe.hr.employeeRelation.service.ITechnologyAgreementService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 技术研发协议控制器
 *
 * @author zhangnn
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/employeeRelation/technologyAgreement")
public class TechnologyAgreementController extends BaseController {

    private final ITechnologyAgreementService technologyAgreementService;

    /**
     * 查询技术研发协议列表
     */
    @SaCheckPermission("employeeRelation:technologyAgreement:list")
    @GetMapping("/list")
    public TableDataInfo<TechnologyAgreementVo> list(TechnologyAgreementBo bo, PageQuery pageQuery) {
        return technologyAgreementService.selectTechnologyAgreementList(bo, pageQuery);
    }

    /**
     * 获取技术研发协议详细信息
     */
    @SaCheckPermission("employeeRelation:technologyAgreement:query")
    @GetMapping(value = "/{agreementId}")
    public R<TechnologyAgreementVo> getInfo(@PathVariable("agreementId") Long agreementId) {
        return R.ok(technologyAgreementService.selectTechnologyAgreementById(agreementId));
    }

    /**
     * 新增技术研发协议
     */
    @SaCheckPermission("employeeRelation:technologyAgreement:add")
    @Log(title = "技术研发协议", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TechnologyAgreementBo bo) {
        return toAjax(technologyAgreementService.insertTechnologyAgreement(bo));
    }

    /**
     * 修改技术研发协议
     */
    @SaCheckPermission("employeeRelation:technologyAgreement:edit")
    @Log(title = "技术研发协议", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TechnologyAgreementBo bo) {
        return toAjax(technologyAgreementService.updateTechnologyAgreement(bo));
    }

    /**
     * 删除技术研发协议
     */
    @SaCheckPermission("employeeRelation:technologyAgreement:remove")
    @Log(title = "技术研发协议", businessType = BusinessType.DELETE)
    @DeleteMapping("/{agreementIds}")
    public R<Void> remove(@PathVariable Long[] agreementIds) {
        return toAjax(technologyAgreementService.deleteTechnologyAgreementByIds(agreementIds));
    }

}
